import java.lang.reflect.Array;
import java.util.Arrays;

public class Test {

    public static void transform(int[] array){
        for (int i = 0;i < array.length;i++){
            array[i] *= 2;
        }
    }

    public static double avg(int[] array){
        double ans = 0.0;
        for (int x : array){
            ans += x;
        }
        ans /= array.length;
        return ans;
    }
    public static void bubbleSort(int[] array){
        //趟数
        for (int i = 0;i < array.length-1;i++){
            boolean flg = false;
            //每趟次数
            for (int j = 0; j < array.length-1-i; j++) {
                if (array[j] > array[j + 1]){
                    int tmp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = tmp;
                    flg = true;
                }
            }
            if (flg == false) return;
        }
    }

    public static void sortArray(int[] array){
        int l = 0;
        int r = array.length - 1;
        while (l < r){
            while (l < r && array[l] % 2 != 0){
                l++;
            }

            while (l < r && array[r] % 2 == 0){
                r--;
            }
            if (l < r){
                int tmp = array[l];
                array[l] = array[r];
                array[r] = tmp;
            }
        }

    }
    public static void func4(int[] array) {
        int i = 0;
        int j = array.length-1;
        while (i < j) {
            //循环外面给了i < j  ,思考这里为什么还需要判断？
            while (i < j && array[i] % 2 != 0) {
                i++;
            }
            //i 下标一定是偶数
            while (i < j && array[j] % 2 == 0) {
                j--;
            }
            int tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
        }
    }

    public static int[] targetNum2(int[] array,int target){
        int[] ans = new int[2];
        Arrays.sort(array);

        int l = 0;
        int r = array.length-1;
        while (l < r){
            if (array[l] + array[r] > target){
                r--;
            }else if(array[l] + array[r] < target){
                l++;
            }else{
                break;
            }
        }
        ans[0] = l;
        ans[1] = r;
        return ans;
    }
    public static int[] targetNum(int[] array,int target){
        int[] ans = new int[2];


        for (int i = 0; i < array.length-1; i++) {
            for (int j = i + 1; j < array.length; j++) {
                if (array[i] + array[j] == target){
                    ans[0] = i;
                    ans[1] = j;
                }
            }
        }

        return ans;
    }

    public static int appearOnce(int[] array){
        int ans = 0;
        for (int i = 0; i < array.length; i++) {
            ans ^= array[i];
        }

        return ans;
    }

    public static int mostEle(int[] array){
        int ans = -1;
        int count = 1;
        for (int x : array){
            if (x != ans){
                count--;
                if (count == 0){
                    ans = x;
                    count = 1;
                }
            }else{
                count++;
            }
        }

        return ans;
    }

    public static boolean isTripleOdd(int[] array){
        int count = 0;
        for (int e : array){
            if (e % 2 != 0){
                count++;
            }else{
                count = 0;
            }
            if (count == 3) return true;
        }

        return false;
    }
    public static void main(String[] args) {
        int array[] = {1,2,34,3,4,5,7,23,12};
        System.out.println(isTripleOdd(array));

/*        int[] array = {2,2,1,1,1,2,2};
        System.out.println(mostEle(array));*/

/*
        int[] array = {1,1,2,2,4,4,3};
        System.out.println(appearOnce(array));
*/

/*        int[] array = {2,7,11,5};
        int target = 9;
        int[] ans = targetNum(array,target);
        System.out.println(Arrays.toString(ans));*/
/*        int[] array = {1,2,3,4,5,6};
        sortArray(array);
        System.out.println(Arrays.toString(array));*/

/*        int[] array = {3,2,1};
        bubbleSort(array);
        System.out.println(Arrays.toString(array));*/
        //System.out.println(avg(array));
        //transform(array);
        //System.out.println(Arrays.toString(array));

    }
    public static void main7(String[] args) {
        int[] array = {1,2,3};
        int[] array2 = new int[array.length * 2];
        System.arraycopy(array,0,array2,0,array.length);
        System.out.println(Arrays.toString(array2));
        /*int[] array = {1,2,3,4,5,6};
        int[] array2 = {1,2,3,4,5,6};
        int[] array3 = new int[10];
        System.out.println(Arrays.toString(array3));
        //Arrays.fill(array3,-1);
        Arrays.fill(array3,1,4,-1);
        System.out.println(Arrays.toString(array3));*/

        //System.out.println(Arrays.equals(array,array2));
        /*int[] array2 = Arrays.copyOfRange(array,1,10);
        int[] array3 = Arrays.copyOf(array,20);

        System.out.println(Arrays.toString(array2));
        System.out.println(Arrays.toString(array3));
        System.out.println(Arrays.binarySearch(array,3));*/

//        int[] array = {1,2,3,4,5};
//        System.out.println(myToString(array));
//
//        int[] array = {1,13,4,2,8};
//        Arrays.sort(array);
//        int[] array2 = Arrays.copyOf(array,array.length);

//        array2[0] = 100;
//        System.out.println(Arrays.toString(array2));
//        System.out.println(Arrays.toString(array));

//        System.out.println(binarySearch(array,13));
//        System.out.println(binarySearch(array,100));

    }

    public static int binarySearch(int[] array,int key){
        int left = 0,right = array.length-1;
        while (left <= right){
            int mid = (left + right) >>> 1;
            if (array[mid] < key){
                left = mid + 1;
            }else if(array[mid] > key){
                right = mid - 1;
            }else{
                return mid;
            }
        }

        return -1;
    }
    public static String myToString(int[] array) {
        String str = "[";
        for (int i = 0; i < array.length; i++) {

            str += array[i];
            if (i != array.length - 1) {
                str += ",";
            }
        }
        str += "]";
        return str;
    }




    public static void move(char pos1,char pos2) {
        System.out.print(pos1+"->"+pos2+" ");
    }

    public static void hanoi(int n,char pos1,char pos2,char pos3) {
        if(n == 1) {
            move(pos1,pos3);
            return;
        }
        hanoi(n-1,pos1,pos3,pos2);
        move(pos1,pos3);
        hanoi(n-1,pos2,pos1,pos3);
    }
    public static int hnt(int n){
        if (n == 1) return n;

        return 1 + 2 * hnt(n-1);
    }

    public static void main6(String[] args) {
        System.out.println(hnt(4));

    }
    public static int max(int a,int b){
        return a > b ? a : b;
    }

    public static double max(double a,double b){
        return a > b ? a : b;
    }
    public static double max(double a,double b,double c){
        double tmp = max(b,c);
        return a > tmp ? a : tmp;
    }

    public static int sum(int a,int b){
        return a + b;
    }
    public static double sum(double a,double b,double c){
        return a + b + c;
    }

    public static void main5(String[] args) {
        System.out.println(sum(1, 2));
        System.out.println(sum(1.5, 2.2,3.3));

        System.out.println(max(2.5, 3.5, 5.8));
        System.out.println(max(4,9));
    }

    public static int fib(int n){
        if (n == 1 || n == 2) return n-1;

        int a = 0,b = 1,tmp = 0;
        for (int i = 3; i <= n; i++) {
            tmp = a + b;
            a = b;
            b = tmp;
        }
        return tmp;
    }

    public static void main4(String[] args) {
        int n = 6;
        System.out.println("斐波那契数列的第" + n + "项是：" + fib(n));
    }
    public static int facFun(int n){
        if (n == 1) return 1;
        return n * facFun(n-1);
    }

    public static int facSum(int n){
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += facFun(i);
        }
        return sum;
    }

    public static int facSum2(int n){
        int sum = 0;
        int tmp = 1;
        for (int i = 1; i <= n; i++) {
            tmp *= i;
            sum += tmp;
        }
        return sum;
    }

    public static void main3(String[] args) {
        int n = 5;
        System.out.println("n的阶乘为：" + facFun(5));
        System.out.println("n的阶乘和为：" + facSum(5));
        System.out.println("n的阶乘和为：" + facSum2(5));
    }
    public static int max2(int n1,int n2){
        if (n1 >= n2) return n1;

        return n2;
    }

    public static int max3(int n1,int n2,int n3){
        return max2(max2(n1,n2),n3);
    }
    public static void main2(String[] args) {
        int maxNum = 0;
        maxNum = max3(2,5,1);
        System.out.println("最大的数是：" + maxNum);
        int[] array = {1,2,3,4,5};

        for (int x : array){
            System.out.println(x + " ");
        }
    }
}
